/******************************************************************************

	COPYRIGHT(C) JONAS 'SORTIE' TERMANSEN 2008, 2009, 2010.

	This file is part of Maxsi Engine.

	Maxsi Engine is free software: you can redistribute it and/or modify it
	under the terms of the GNU Lesser General Public License as published by
	the Free Software Foundation, either version 3 of the License, or (at your
	option) any later version.

	Maxsi engine is distributed in the hope that it will be useful, but WITHOUT
	ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
	FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
	for more details.

	You should have received a copy of the GNU Lesser General Public License
	along with Maxsi Engine. If not, see <http://www.gnu.org/licenses/>.

	MaxsiEngine.dll
	A general purpose C++ library for the Maxsi Technology Project.

	MaxsiInstallScript.cpp
	Functions that execute install scripts, and interfaces for declaring
	functions that can be used by insall scripts.

******************************************************************************/

//=============================================================================
//	TODO: Please replace this with Angelscript in the future.
//=============================================================================

#ifndef MaxsiInstallScript_H
#define MaxsiInstallScript_H

BeginMaxsiNamespace

//=============================================================================
//	A class containing all the parameters sent as input to a MIS function.
//=============================================================================
CLASSLINK MaxsiInstallScriptInput
{
public:
	List	Var;
	size_t	Size;

public:
	MESTR*	operator[]	( size_t					val		);
	void	operator=	( List						Input	);
	List	operator=	( MaxsiInstallScriptInput	Input	);
	List	operator()	(									){	return Var;}

	MaxsiInstallScriptInput	();
	MaxsiInstallScriptInput	(List Input);
};

//=============================================================================
//	Common macros used to declare MIS-enabled functions
//=============================================================================
#define MISInput MaxsiInstallScriptInput
#define MISFUNCH(Name			) int Name (MISInput In)
#define MISFUNC(Name,Permission) \
class	MISFUNC_Register_##Name \
{ \
public: \
	MISFUNC_Register_##Name() \
	{ \
	MISFuncRegister( #Name , &Name , _MESTR( #Permission ) ); \
	} \
} MISFUNC_Register_Instance_##Name; \
int Name (MISInput In)

//=============================================================================
//	Function pointers
//=============================================================================
typedef int (* MISFunc)(MISInput);

//=============================================================================
//	Type declarations
//=============================================================================
typedef MESTR* MISPermission;

struct MISFuncS
{
	MESTR*			Name;
	MISFunc			Pointer;
};

struct MISFuncP
{
	MESTR*			Name;
	List			Functions;
};

//=============================================================================
//	MIS Script functions
//=============================================================================
LINK	bool			MISFuncRegister		(MESTR* Name, MISFunc Pointer, MISPermission Permission);
LINK	MISFunc			MISFuncGet			(MESTR* Name, MISPermission Permission);
LINK	int				MISRun				(MESTR* Script, MISPermission Permission);

EndMaxsiNamespace

#endif
